home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2003 May / PFA0503.iso / fullversioner / webmenubuilder / WebMenuBuilder2demo / setup.exe / {app} / help / CircularStringBuffer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-03-22  |  1.1 KB  |  54 lines

  1. public class CircularStringBuffer {
  2.    private int insertionIndex;
  3.    private int size;
  4.    private int bufferSize;
  5.    private char[] contents;
  6.  
  7.    public CircularStringBuffer(int var1) {
  8.       if (var1 < 0) {
  9.          throw new IllegalArgumentException("bufferSize < 0");
  10.       } else {
  11.          this.bufferSize = var1;
  12.          this.contents = new char[var1];
  13.          this.size = 0;
  14.          this.insertionIndex = 0;
  15.       }
  16.    }
  17.  
  18.    public void append(char var1) {
  19.       if (this.bufferSize != 0) {
  20.          this.contents[this.insertionIndex] = var1;
  21.          if (this.size < this.bufferSize) {
  22.             ++this.size;
  23.          }
  24.  
  25.          ++this.insertionIndex;
  26.          this.insertionIndex %= this.bufferSize;
  27.       }
  28.  
  29.    }
  30.  
  31.    public int getSize() {
  32.       return this.size;
  33.    }
  34.  
  35.    public int getBufferSize() {
  36.       return this.bufferSize;
  37.    }
  38.  
  39.    public String toString() {
  40.       if (this.bufferSize != 0) {
  41.          if (this.size >= this.bufferSize && this.insertionIndex != 0) {
  42.             StringBuffer var1 = new StringBuffer(this.bufferSize);
  43.             var1.append(this.contents, this.insertionIndex, this.bufferSize - this.insertionIndex);
  44.             var1.append(this.contents, 0, this.insertionIndex);
  45.             return var1.toString();
  46.          } else {
  47.             return new String(this.contents, 0, this.size);
  48.          }
  49.       } else {
  50.          return "";
  51.       }
  52.    }
  53. }
  54.